﻿using Stardust.Client;
using Stardust.Common.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ClientTest
{

    public class User
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Msg { get; set; }

        public Task<string> GetStr(int count)
        {
            return new Task<string>(() =>
            {
                return new string('a', count);
            });
        }

        public string GetStr1(int count)
        {
            return new string('a', count);
        }
    }

    class Program
    {
        public static string GetMaskPhone(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return str;
            }
            if (str.Length == 11)
            {
                return str.Substring(0, 3) + "****" + str.Substring(7);
            }
            var herf = str.Length / 2;
            return new string('*', herf) + str.Substring(herf);
        }

        static void Main(string[] args)
        {

            //Console.WriteLine(GetMaskPhone("15824564852"));
            //return;

            StardustClient.SetConfigCenterUrl("http://localhost:85");
            while (true)
            {
                var node1Client = new StardustClient("node1", "1.2");
                try
                {
                    var result = node1Client.Invoke<List<User>>("user", "GetUsers", null);
                    Console.WriteLine(SerializerHelper.SerializeToString(result));
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
                Thread.Sleep(500);
            }
        }
    }
}
